//
//  VVComposeButton.swift
//  Weibo
//
//  Created by 王惠平 on 2017/4/4.
//  Copyright © 2017年 Will Wang. All rights reserved.
//

import UIKit

class VVComposeButton: UIButton {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        //使用原始图片居中显示
        imageView?.contentMode = .center
        
        //文字居中
        titleLabel?.textAlignment = .center
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        //设置图片的y轴
        imageView?.frame.origin.y = 0
        imageView?.frame.origin.x = 0
        
        //设置图片的大小
        imageView?.frame.size.width = bounds.size.width
        imageView?.frame.size.height = bounds.size.width
        
        //设置titleLabel的y轴,但钱按钮的高度减去按钮的高度表示titleLabel的y轴
        titleLabel?.frame.origin.y = bounds.size.width
        titleLabel?.frame.origin.x = 0
        
        //设置文字的大小
        titleLabel?.frame.size.width = bounds.size.width
        titleLabel?.frame.size.height = bounds.size.height - bounds.size.width
    }
    
    
}
